import java.util.Arrays;

public class Solution1652 {
    public int[] decrypt(int[] code, int k) {
        int[] ans=new int[code.length];
        for (int i=0;i<code.length;i++){
            int t=0;
            if (k>=0){
                for (int j=0;j<k;j++){
                    t=t+code[(i+j+1)%code.length];
                }
            }else {
                for (int j=0;j<-k;j++){
                    t=t+code[(i-j-1+code.length)%code.length];
                }
            }
            ans[i]=t;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1652().decrypt(new int[]{5, 7, 1, 4,}, 3)));
    }
}
